package org.jeecg.modules.kuner.sysconf;

import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.util.RedisUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * @Description:
 * @Author: Planifolia.Van
 * @Date: 2025/3/3 14:11
 */
@Service
public class SysConfigService {

    @Resource
    private RedisUtil redisUtil;


    public void setOrderIncomeRate(BigDecimal rate) {
        if (rate == null) {
            throw new JeecgBootException("数值错误！");
        }
        if (rate.compareTo(BigDecimal.ZERO) < 0 || rate.compareTo(BigDecimal.ONE) >= 0) {
            throw new JeecgBootException("分佣比例正确区间为 [0,1)");
        }
        redisUtil.set(CommonConstant.ORDER_INCOME_RATE_KEY, rate);
    }

    public BigDecimal getOrderIncomeRate() {
        Object o = redisUtil.get(CommonConstant.ORDER_INCOME_RATE_KEY);
        if (o instanceof BigDecimal){
            return (BigDecimal) o;
        }
        return CommonConstant.ORDER_INCOME_RATE;
    }

}
